package com.gamemost.templestay;

import java.util.Locale;

import com.gamemost.managers.ResourcesManager;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class SettingMain extends Activity {
	String[] langs;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_setting_main);		
		ListView lv = (ListView) findViewById(R.id.listSetting);
		updateTexts();
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(
				getBaseContext(), android.R.layout.simple_list_item_1,
				new String[] { getResources().getString(
						R.string.english_default) });
		langs = getResources().getStringArray(
				R.array.list_lang_values);
		lv.setAdapter(adapter);
		lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				AlertDialog.Builder builder = new AlertDialog.Builder(
						SettingMain.this);
				builder.setTitle("")
						.setSingleChoiceItems(
								langs, Config.lang,
								new OnClickListener() {

									@Override
									public void onClick(DialogInterface dialog,
											int which) {
										// TODO Auto-generated method stub
										Config.lang = which;
										updateTexts();
										dialog.dismiss();
										finish();
									}
								});
				builder.create().show();

			}
		});
	}
	public void updateTexts() {
		// TODO Auto-generated method stub		
		System.out.println(getResources().getString(R.string.app_name)+" ===========");
		ResourcesManager.ac.updateTexts();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.setting_main, menu);
		return true;
	}

}
